from parser import *

class Problem():
    def __init__(self, problem_definition_list):
        self.problem_name = problem_definition_list[0]
	self.domain_name = problem_definition_list[1]
        self.requirements = problem_definition_list[2]
        self.objects = problem_definition_list[3]
        self.init = problem_definition_list[4]
        self.goal = problem_definition_list[5]

    def instantiate(strips_problem_file):
	parsed_strips_file = parse_strips_file(file(strips_problem_file)) #Parse the file
        problem_generator = parse_problem(parsed_strips_file) #get the problem class generator
	prob_def = list(problem_generator)        

	return Problem(prob_def)
    instantiate = staticmethod(instantiate)

    def __str__(self):
	return "<Problem: %s>" %(self.problem_name)

    def __repr__(self):
	return str(self)

    def debug_print(self):
        print "Problem %s: Domain %s Requirements [%s]" % (self.problem_name, self.domain_name, self.requirements)
        
	print "Objects:"
        for obj in self.objects:
            print "  %s" % obj

	print "Init:"
        for init_cond in self.init:
            print "  %s" % init_cond

        print "Goals:"
        print self.goal.debug_print()
    
    def __repr__(self):
	return "Problem %s: " % (self.problem_name)

if __name__ == "__main__":
    a = Problem.instantiate("task.pddl") #test
